package com.yhsoft.sys.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yhsoft.common.response.PageResult;
import com.yhsoft.common.vo.Result;
import com.yhsoft.sys.controller.Response.MessageOutVo;
import com.yhsoft.sys.service.IMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * <p>
 * 通知信息表 前端控制器
 * </p>
 *
 * @author yyyyyyyh
 * @since 2023-11-27
 */
@Api(tags = {"N-消息相关接口"})
@RestController
@RequestMapping("/sys/message")
public class MessageController {
    @Autowired
    private IMessageService iMessageService;

    @ApiOperation("获取未读消息数量,前端定时获取")
    @GetMapping("/getNum")
    public Result<?> getNum(){
        String num = iMessageService.getNum();
        return Result.success(num);
    }

    @ApiOperation("获取所有消息列表")
    @GetMapping("/list")
    public Result<PageResult<MessageOutVo>> list(@RequestParam(value = "pageNo") Long pageNo,
                                                 @RequestParam(value = "pageSize") Long pageSize){
        IPage<MessageOutVo> iPage = iMessageService.getList(pageNo, pageSize);
        return Result.success(PageResult.valueOf(iPage));
    }

    @ApiOperation("消息已读")
    @PostMapping("/read")
    public Result<?> read(@NotNull(message = "公告id不能为空") @RequestParam Integer id){
        String msg = iMessageService.read(id);
        return Result.success(msg);
    }
}
